package cn.kgc.web;

import cn.kgc.entity.Project;
import cn.kgc.service.ProjectService;
import cn.kgc.service.impl.ProjectServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@WebServlet(urlPatterns = "/project")
public class ProjectServlet extends HttpServlet {
    //查询各个科目的平均成绩，以json方式返回给jsp，及图表显示
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        ProjectService projectService = new ProjectServiceImpl();
        List<Project> projectList = projectService.search();
        String listjson = JSON.toJSONString(projectList);
        out.print(listjson);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
